package org.openarchitectureware.recipe2.predefs;


import org.apache.bcel.classfile.JavaClass;
import org.openarchitectureware.recipe2.findbugs.BCELUtil;
import org.openarchitectureware.recipe2.findbugs.FindBugsUtil;
import org.openarchitectureware.recipe2.findbugs.PredefInstance;
import org.openarchitectureware.recipe2.findbugs.XMLParameterIteratingDetector2;

import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.classfile.ClassDescriptor;

public class JavaClassExists extends XMLParameterIteratingDetector2 {

	public JavaClassExists(BugReporter bugReporter) {
		super(bugReporter);
	}

	public void finishPass(PredefInstance instance) {
		String javaClassName = instance.getParameter("javaClassName");
		JavaClass javaClass = BCELUtil.getJavaClass(bugReporter, javaClassName);
		if (javaClass == null) {
			BugInstance bugInstance = createBugInstance(instance, javaClassName, NORMAL_PRIORITY);
			FindBugsUtil.configureMissingClassDetails(javaClassName, bugInstance);
			bugReporter.reportBug(bugInstance);
		}
	}

	@Override
	protected String getBugPattern() {
		return "RC_JAVA_CLASS_EXISTS";
	}

	@Override
	protected String getPredefName() {
		return "javaClassExists";
	}

	public void visitClass(ClassDescriptor classDescriptor, PredefInstance instance) {
	}

}
